﻿
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline;


using JohnWells.GameLevel;
using JohnWells.GameLevel.Vertices;
using JohnWells.GameLevel.ContentPipeline.Leadwerks14;

namespace JohnWells.GameLevel.ContentPipeline.Serialization
{

    public sealed class TriggerContent
    {
        public KeyValuePair<string, object>[] Keys;
        public Vector3 MinPos;
        public Vector3 MaxPos;

        public TriggerContent(Brush brush)
        {
            bool first = true;
            Keys = new KeyValuePair<string, object>[brush.Items.Length];
            int index = 0;
           
            // Copy items (optionally in the future change the type of the value object to reflect color, position, etc)
            foreach (KeyValuePair<string, string> item in brush.Items)
                Keys[index++] = new KeyValuePair<string, object>(item.Key, item.Value);

            foreach (BrushFace face in brush.AllFaces)
            {
                foreach (BrushVertex vertex in face.Vertices)
                {
                    if (first)
                    {
                        MinPos = MaxPos = vertex.Position;
                        first = false;
                    }
                    else
                    {
                        if (MinPos.X > vertex.Position.X) MinPos.X = vertex.Position.X;
                        if (MinPos.Y > vertex.Position.Y) MinPos.Y = vertex.Position.Y;
                        if (MinPos.Z > vertex.Position.Z) MinPos.Z = vertex.Position.Z;

                        if (MaxPos.X < vertex.Position.X) MaxPos.X = vertex.Position.X;
                        if (MaxPos.Y < vertex.Position.Y) MaxPos.Y = vertex.Position.Y;
                        if (MaxPos.Z < vertex.Position.Z) MaxPos.Z = vertex.Position.Z;
                    }
                }
            }
        }
    }
}